package com.zdp.controller.center;

import com.zdp.common.domain.PagedGridResult;
import com.zdp.common.domain.ResultInfo;
import com.zdp.common.util.ResultInfoUtil;
import com.zdp.controller.BaseController;
import com.zdp.service.center.MyOrdersService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sesshomaru
 * @date 2021/8/14 19:55
 */
@RestController
@RequestMapping("myorders")
public class MyOrdersController extends BaseController {

    @Autowired
    private MyOrdersService myOrdersService;

    @PostMapping("/query")
    public ResultInfo query(
            //@ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam String userId,
            //@ApiParam(name = "orderStatus", value = "订单状态", required = false)
            @RequestParam Integer orderStatus,
            //@ApiParam(name = "page", value = "查询下一页的第几页", required = false)
            @RequestParam Integer page,
            //@ApiParam(name = "pageSize", value = "分页的每一页显示的条数", required = false)
            @RequestParam Integer pageSize
    ) {

        if (StringUtils.isBlank(userId)) {
            return ResultInfoUtil.buildError(null);
        }
        if (page == null) {
            page = 1;
        }
        if (pageSize == null) {
            pageSize = COMMON_PAGE_SIZE;
        }

        PagedGridResult grid = myOrdersService.queryMyOrders(userId,
                orderStatus,
                page,
                pageSize);

        return ResultInfoUtil.buildSuccess(grid);

    }
}
